/*


 */

package jas.http.response;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

/**
 * Describes the body of an HTTP response.
 * 
 * Reading the body into memory can be too expensive, which is why 
 * this interface allows streaming the body directly from its source.
 */
public interface ResponseBody {
	/**
	 * Prints the body using the specified output stream.
	 * 
	 * This method may also acquire the body, for exaple by
	 * reading from the disk or downloading from another server.
	 * 
	 * @param output stream to print the body into.
	 * @throws IOException thrown if the output stream throw an exception, or if the body could not be acquired.
	 */
    void print(OutputStream output) throws IOException;
    
    /**
     * Provides the content length in bytes, used for the <code>Content-Length</code> header.
     * @return number of bytes in the body.
     */
    long getContentLength();
    
    /**
     * Provides the content MIME type, used for the <code>Content-Type</code> header.
     * @return the MIME content type of the body, or an empty string if it is unknown.
     */
    String getContentType();
    
    /**
     * Provides the content's encoding, used for the <code>Content-Encoding</code> header.
     * @return encoding of the content, or an empty string if it is unknown.
     */
    String getContentEncoding();
    
    /**
     * @return the modified date of the body, if available, or the current date if it is dynamic or unknown.
     */
    Date getModifiedDate();
}
